<template>
    <div>
        <div class="card card-custom gutter-b example example-compact" id="tableReceiveBody">
            <div class="card-body">
                <!--查询条件-->
                <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                    <div class="m-portlet__body">
                        <div class="form-group m-form__group row">
                            <label class="col-form-label">标题:</label>
                            <div class="col-md-2">
                                <input type="text" class="form-control" v-model="searchForm.title" placeholder="请输入">
                            </div>
                            <label class="col-form-label">类型:</label>
                            <div class="col-lg-2">
                                <el-select v-model="searchForm.type" placeholder="请选择">
                                    <el-option value="">请选择</el-option>
                                    <el-option
                                        v-for="item in [{ value: 0, label: '系统' }, { value: 1, label: '修改密码' }, { value: 2, label: '工作流' }]"
                                        :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </div><label class="col-form-label">状态:</label>
                            <div class="col-lg-2">
                                <el-select v-model="searchForm.status" placeholder="请选择">
                                    <el-option value="">请选择</el-option>
                                    <el-option v-for="item in [{ value: 0, label: '未读' }, { value: 1, label: '已读' }]"
                                        :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </div>
                            <b-button :pressed="false" variant="btn btn-light-primary font-weight-bold font-size-sm py-3 px-8 mr-2 " @click="search()"><span><i
                            class="flaticon-search-magnifier-interface-symbol"></i><span>查 询</span></span></b-button>
                            <b-button :pressed="false" variant="btn btn-light font-weight-bold font-size-sm py-3 px-8 mr-2 " @click="resetAll()">
                            <span><i class="flaticon2-refresh"></i><span>重 置</span></span></b-button>
                            <!-- :disabled="this.sels.length === 0" 如果没有数据让删除按钮失效 -->
                            <button class="btn btn-light-danger font-weight-bold mr-2"
                            v-permission="{ action: '/sysNotifyReceiver/delete', effect: 'display' }"
                            @click="delSysNotifyReceiver"
                                :disabled="this.sels.length === 0">
                                <span><i class="far fa-trash-alt"></i><span>删 除</span></span>
                            </button>
                        </div>
                    </div>
                    <div class="m-portlet__foot m-portlet__no-border m-portlet__foot--fit">
                        <div class="m-form__actions m-form__actions--solid">
                            <div class="row">
                                <div class="col m--align-left">
                                </div>
                                <div class="col m--align-right">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--分页组件-->
            <el-table style="width: 100%" stripe border @selection-change="handleSelectionChange" highlight-current-row
                :data="dataList">
                <template slot="empty">
                    <el-empty description="暂无数据"></el-empty>
                </template>
                <!-- 复选框 -->
                <el-table-column type="selection" width="40"></el-table-column>
                <el-table-column label="序号" min-width="50">
                    <template slot-scope="scope">
                        {{ scope.$index + 1 }}
                    </template>
                </el-table-column>
                <el-table-column align="left" prop="title" show-overflow-tooltip label="标题"></el-table-column>
                <el-table-column align="left" prop="type" show-overflow-tooltip label="类型">
                    <template slot-scope="scope">
                        <div v-if="scope.row.type == 0">
                            <b-badge class="mr-1" variant="primary">系统</b-badge>
                        </div>
                        <div v-else-if="scope.row.type == 1">
                            <b-badge class="mr-1" variant="warning">修改密码</b-badge>
                        </div>
                        <div v-else-if="scope.row.type == 2">
                            <b-badge class="mr-1" variant="success">工作流</b-badge>
                        </div>
                        <div v-else>
                            <b-badge class="mr-1" variant="secondary">未知</b-badge>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column align="left" prop="status" show-overflow-tooltip label="状态">
                    <template slot-scope="scope">
                        <div v-if="scope.row.status == 0" class="symbol symbol-40 symbol-circle symbol-light-warning">
                            <span class="symbol-label font-size-h8">未读</span>
                        </div>
                        <div v-else-if="scope.row.status == 1" class="symbol symbol-40 symbol-circle symbol-light-primary">
                            <span class="symbol-label font-size-h8">已读</span>
                        </div>
                        <div v-else class="symbol symbol-40 symbol-circle symbol-light-danger">
                            <span class="symbol-label font-size-h8">未知</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="fromUserName" label="发送者" min-width="150"></el-table-column>
                <el-table-column align="center" prop="receiveTime" label="接收日期" min-width="180"></el-table-column>
                <el-table-column align="center" label="操作" fixed="left">
                    <template slot-scope="scope">
                        <!--scope.row当前行的对象-->
                        <button @click="getNotifyDetail(scope.row)" class="btn btn-link" title="详情">详 情</button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block">
                <el-pagination hide-on-single-page @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="pageNo" :page-sizes="[5, 10, 30, 50]" :page-size="pageSize"
                    layout="->,total, sizes, prev, pager, next, jumper" :total="totalCount">
                </el-pagination>
            </div>
        </div>
        <NotifyReceiveDetail ref="notifyReceiveDetailRef"></NotifyReceiveDetail>
    </div>
</template>
<style scoped>
.card.card-custom {
    box-shadow: 0px 0px 30px 0px #fff !important;
}
</style>

<script>
import { SET_BREADCRUMB } from "@/store/breadcrumbs.module";
import NotifyReceiveDetail from "@/view/sys/sys-notify/sys-notify-receive-detail.vue";
import Swal from "sweetalert2";
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            searchForm: { title: "", type: "", status: "", },
            dataList: [],
            sels: [], //当前选框选中的值
            pageNo: 1,      // 默认当前是第一页
            pageSize: 5,    // 当前每页的数据是5条
            totalCount: 0   // 总数默认为0
        }
    },
    components: {
        NotifyReceiveDetail,
    },
    mounted() {
        this.initList();   // 按当前的页号和每页的数据量进行查询
    },
    methods: {
        initList() {
            showWating({ renderBody: "tableReceiveBody" });
            this.searchForm.usePageNo = true;//采用第几页进行分页（兼容）
            this.searchForm.pageSize = this.pageSize;//页面显示记录条数，在页面显示每页显示多少项的时候
            this.searchForm.pageNo = this.pageNo;//开始的记录序号    
            apiUtil.query(process.env.VUE_APP_SYS_API + "/sysNotifyReceiver/list", this.searchForm).then(({ data }) => {
                this.dataList = data.data;//给结果集赋值
                this.totalCount = data.total;// 获取当前数据的总数    
            });
        },

        handleSelectionChange(sels) {//获取选中的值
            this.sels = sels;
            console.log("选中的值", sels.map((item) => item.id));
        },
        addSysNotify() {//新建
            this.$refs.notifyAddRef.showModal()
        },
        delSysNotifyReceiver() { // 删除
            if (this.sels.length === 0) {
                handleAlert("请选择删除的数据", "warning", 3)
                return;
            }
            // 删除前提示
            this.$confirm("确认删除记录吗?", "提示", { type: "warning", }).then(() => {
                let ids = this.sels.map((item) => item.id);
                let params = {};
                apiUtil.delete(process.env.VUE_APP_SYS_API + "/sysNotifyReceiver/delete?id=" + ids.join(","), params).then(data => {
                    if (data.data.success) {
                        handleAlert("删除成功", "success", 3);
                        this.search();
                    } else {
                        handleAlert("删除失败", "error", 3);
                    }
                });
            }).catch(() => { });//注意这里，这里是重点！！！;        
        },
        handleSizeChange(val) { // 修改每页所存数据量的值所触发的函数
            this.pageSize = val;  // 修改页的大小
            this.initList();       // 按新的pageNo和pageSize进行查询
        },
        handleCurrentChange(val) { // 修改当前页所触发的函数
            this.pageNo = val;       // 更新当前的页
            this.initList();          // 按新的pageNo和pageSize进行查询
        },
        search() {
            this.pageNo = 1;       // 更新当前的页
            this.initList();          // 按新的pageNo和pageSize进行查询
        },
        resetAll() {
            Object.assign(this.$data.searchForm, this.$options.data().searchForm);
            this.search();
        },
        getNotifyDetail(row) {
            this.$refs.notifyReceiveDetailRef.showModal(row.id);
        },
    }
};
</script>